<?php

class FileView extends PageView {

    /**
     * Draw the list with files and link the files.
     *
     * @param array $files An array with the file-names
     * @param string $path String with the path to the files
     *
     * @return string 
     */
    public function showFileList($files) {
        $retStr = "" ;

        if($files) {
            foreach ($files as $file) {
                $retStr .= "<a href=\"".$this->model->getPath().$file."\">$file</a><br />\n" ;
            }
        }

        return $this->addDiv($retStr, array("class"=>"fileList")) ;
    
    }
    
    /**
     * Draw the uploadform and add it to a div.
     *
     * @return string
     */
    public function showFileUploadForm() {
        return $this->addDiv("
            <form action=\"?fileUpload\" method=\"post\" enctype=\"multipart/form-data\">
                <input type=\"file\" name=\"file\" id=\"file\"/>
                <input type=\"submit\" id=\"uploadFile\" value=\"Upload file\" />
            </form>
            ", array("class"=>"fileUpload")) ;
    }

    /**
     * Get and check if the uploaded file exists
     *
     * $return file|false
     */

    public function getUploadedFile() {
        return (isset($_FILES['file'])) ? $_FILES['file'] : false ;
    }

}
